C Programming arrays, I dont understand how I would go about making this program, If anyone can just guide me through the basic outline please :) [on hold]
Posted
by
Rashmi Kohli
on Programmers
See other posts from Programmers
or by Rashmi Kohli
Published on 2013-11-07T23:20:44Z
Indexed on
2013/11/08
4:17 UTC
Read the original article
Hit count: 214
c
Problem
The temperature of a car engine has been measured, from real-world experiments, as shown in the table and graph below:
Time (min) Temperature (oC)
0 20
1 36
2 61
3 68
4 77
5 110
Use linear regression to find the engine’s temperature at 1.5 minutes, 4.3 minutes, and any other time specified by the user.
Background
In engineering, many times we measure several data points in an experiment, but then we need to predict a value that we have not measured which lies between two measured values, such as the problem statement above. If the relation between the measured parameters seems to be roughly linear, then we can use linear regression to find the relationship between those parameters. In the graph of the problem statement above, the relation seems to be roughly linear. Hence, we can apply linear regression to the above problem.
Assuming y {y0, y1, …yn-1} has a linear relation with x {x0, x1, … xn-1}, we can say that:
y = mx+b
where m and b can be found with linear regression as follows:
For the problem in this lab, using linear regression gives us the following line (in blue) compared to the measured curve (in red). As you can see, there is usually a difference between the measured values and the estimated (predicted) values. What linear regression does is to minimize those differences and still give us a straight line (blue).
Other methods, such as non-linear regression, are also possible to achieve higher accuracy and better curve fitting.
Requirements
Your program should first print the table of the temperatures similar to the way it’s printed in the problem statement. It should then calculate the temperature at minute 1.5 and 4.3 and show the answers to the user. Next, it should prompt the user to enter a time in minutes (or -1 to quit), and after reading the user’s specified time it should give the value of the engine’s temperature at that time. It should then go back to the prompt.
Hints
•Use a one dimensional array to store the temperature values given in the problem statement. •Use functions to separate tasks such as calculating m, calculating b, calculating the temperature at a given time, printing the prompt, etc. You can then give your algorithm as well as you pseudo code per function, as opposed to one large algorithm diagram or one large sequence of pseudo code.
© Programmers or respective owner